import React from 'react';
import {Form, Input, Radio} from 'antd';
import {WeaBrowser, WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const FormItem = Form.Item;
const RadioGroup = Radio.Group;

import FormGroup from './base/FormGroup';
import FormItem4Title from './base/FormItem4Title';
import FormItem4ShowNum from './base/FormItem4ShowNum';
import FormItem4LinkMode from './base/FormItem4LinkMode';
import FormItem4Field from './base/FormItem4Field';

// 未读文档
export default class Content_6 extends React.Component {
    state = {
        docSourceType: this.props.data.eContent.eDocSourceType.selected,
        docCatalogs: this.props.data.eContent.docCatalogs,
        virtualCatalogs: this.props.data.eContent.virtualCatalogs,
        docCatalogsNames: this.props.data.eContent.docCatalogsNames,
        virtualCatalogsNames: this.props.data.eContent.virtualCatalogsNames
    };
    constructor(props) {
        super(props);
        this.onChange = this.onChange.bind(this);
    }
    onChange(type, ids, names, datas){
        if(type ==='docCatalogs'){
            this.setState({
                docCatalogs: ids,
                docCatalogsNames: datas
            });
            this.props.form.setFieldsValue({'eContentDocCatalogs': ids});
        }else if(type ==='virtualCatalogs'){
            this.setState({
                virtualCatalogs: ids,
                virtualCatalogsNames: datas
            });
            this.props.form.setFieldsValue({'eContentVirtualCatalogs': ids});
        }
    }
    render() {
        const {eShareLevel, eContent} = this.props.data;
        const {eDocSourceType} = eContent;
        const {getFieldProps} = this.props.form;
        const {formItemLayout} = this.props;
        let eFormItem4DocFrom = <div></div>;
        if (eShareLevel == '2') {
            getFieldProps('eContentDocCatalogs', {initialValue: this.state.docCatalogs});
            getFieldProps('eContentVirtualCatalogs', {initialValue: this.state.virtualCatalogs});
            const eDocSourceTypeProps = getFieldProps('eContentDocSourceType', {initialValue: this.state.docSourceType});
            const eDocSourceTypeOptions = eDocSourceType.options.map((item, index) => {
                const { docCatalogsNames,virtualCatalogsNames } = this.state;
                const replaceDatas = { "docCatalogs" : docCatalogsNames, "virtualCatalogs" : virtualCatalogsNames } [item.type] || [];
                const weatype = { "docCatalogs" : 'doccategory',"virtualCatalogs" : 'docdummy' } [item.type] || '';
                return (
                    <Radio key={index} style={{display: 'block'}} value={item.value}>
                        {item.label}
                        {item.type != 'allDocs' ?
                            <div style={{display: 'inline-block', width: '410px', margin: '5px', verticalAlign: 'middle'}}>
                                <WeaBrowser
                                    type={weatype}
                                    isMultCheckbox = {true}
                                    isSingle={false}
                                    replaceDatas={ replaceDatas || [] }
                                    onChange={(ids, names, datas) => this.onChange(item.type, ids, names, datas)} 
                                />
                            </div> : ''
                        }
                    </Radio>
                );
            });
            eFormItem4DocFrom = (
                <FormItem label="文档来源" {...formItemLayout}>
                    <RadioGroup {...eDocSourceTypeProps}>
                        {eDocSourceTypeOptions}
                    </RadioGroup>
                </FormItem>
            );
        }

        return (
            <Form horizontal className="esetting-form">
                <FormGroup title={getLabel(	81711, '基本信息')}>
                    <FormItem4Title {...this.props}/>
                    <FormItem4ShowNum {...this.props}/>
                    <FormItem4LinkMode {...this.props}/>
                    <FormItem4Field {...this.props}/>
                    {eFormItem4DocFrom}
                </FormGroup>
            </Form>
        );
    }
}